@use "../extends";
@use "../mixins";

form {
  #main_content > &.alchemy {
    max-width: 600px;
    padding: var(--spacing-2);
    margin: 2em auto;
  }

  &.button-with-confirm {
    display: inline-block;
    margin: 0;
    padding: 0;
  }

  &.edit_page textarea {
    height: 67px;
  }

  .control-label {
    @include mixins.form-label;
  }

  .inline-label {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-1);
  }

  .input {
    padding: var(--spacing-1) 0;
    @include mixins.clearfix;

    input[type="url"],
    input[type="number"],
    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea,
    select,
    .select2-container,
    .autocomplete_tag_list,
    .tinymce_container {
      width: var(--form-right-column-width);
      float: right;
    }

    textarea {
      padding-top: 7px;
    }

    .input > select,
    .input > .select2-container {
      width: 100%;
    }

    > .autocomplete_tag_list {
      .select2-container,
      .select2-choices {
        width: 100%;
      }
    }

    ::-webkit-input-placeholder {
      line-height: 16px;
    }

    select,
    .select2-container {
      margin: var(--spacing-1) 0;
    }

    &.boolean {
      margin-left: var(--form-left-column-width);

      input {
        margin: 0;
        margin-right: var(--spacing-0);
        margin-left: 1px;
        vertical-align: middle;
      }

      label {
        width: 100%;
        text-align: left;
        padding: 0;
        margin: 0;
        float: none;
        margin-left: var(--spacing-1);
        vertical-align: middle;
      }
    }

    label.checkbox {
      display: flex;
      align-items: center;
      gap: var(--spacing-1);
      margin: var(--spacing-0) 0;

      input {
        margin-right: var(--spacing-0);
        margin-left: 1px;
      }
    }

    &.language_locale small.error {
      @include mixins.form-hint(
        $background-color: var(--notice-error-background-color),
        $border-color: var(--notice-error-border-color),
        $color: var(--notice-error-text-color)
      );
      text-align: left;
    }
  }

  .field_with_errors {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea,
    .select2-choices {
      @extend %field-with-error;
    }

    .select2-choice,
    .select2-choices {
      border-color: var(--notice-error-border-color);
      color: var(--notice-error-text-color);
      margin-bottom: var(--spacing-1);

      input[type="text"] {
        box-shadow: none;
      }
    }

    label {
      color: var(--notice-error-text-color);
    }
  }

  input:invalid:focus {
    @extend %field-with-error;
  }

  small.error {
    color: var(--notice-error-text-color);
    display: block;
    margin-left: var(--form-left-column-width);
    line-height: 1.5em;
    clear: both;
    text-align: right;
    margin-bottom: 0.25em;
  }

  .input-addon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--form-field-addon-width);
    height: var(--form-field-height);
    position: absolute;
    bottom: var(--spacing-2);
    --select-background-image: none;

    select {
      width: 100%;
      padding: 0;
      text-align: center;
    }

    &.left {
      left: 0;

      select {
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
      }
    }

    &.right {
      left: unset;
      right: 0;

      select {
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
      }

      &.second {
        left: unset;
        right: var(--form-field-addon-width);

        select {
          border-right-width: 0;
          border-top-right-radius: 0;
          border-bottom-right-radius: 0;
        }
      }
    }
  }

  .inline-input {
    align-items: center;
    display: flex;
    margin: 0 calc(-1 * var(--spacing-1));

    .left-column,
    .right-column {
      padding: 0 var(--spacing-1);
    }

    .left-column {
      width: var(--form-right-column-width);
    }

    .right-column {
      width: var(--form-left-column-width);
    }

    button,
    .button,
    input[type="url"],
    input[type="text"],
    input[type="email"],
    input[type="submit"],
    input[type="password"] {
      width: 100%;
    }
  }

  .control_group {
    width: var(--form-right-column-width);
    padding-top: var(--spacing-1);
    float: right;
  }

  .check_boxes .control_group {
    padding-top: 0.6em;
  }

  .input .hint {
    @include mixins.form-hint;
    margin-left: var(--form-left-column-width);

    a[href] {
      color: var(--hint-text-link-color);
    }
  }

  .submit {
    padding: var(--spacing-1) 0;
    text-align: right;
  }

  .input-column {
    padding: 0 var(--spacing-1);

    input[type] {
      float: none;
      width: 100%;
    }
  }

  .input-row {
    display: flex;

    .input-column {
      &:first-of-type {
        padding-left: 0;
      }

      &:last-of-type {
        padding-right: 0;
      }
    }
  }
}

.input-column > label {
  display: block;
  margin-top: calc(var(--spacing-1) + 1);
}
